
export default { //prams 为我们需要调用的接口API的参数 下面会贴具体代码

	methods: {
		isLogin() {
			let _this = this
			//因为我们的GET和POST请求结构不同这里我们做处理，大家根据自己后台接口所需结构灵活做调整
			let openid = uni.getStorageSync('openid');
			if (openid) {
				//已经登录
				let routes = getCurrentPages()
				let curRoute = routes[routes.length - 1].route //获取当前页面路由
				return openid
				console.log(curRoute)
				
			} else {
				//未登录
				uni.login({
				  success (res) {
				    if (res.code) {
				      //发起网络请求
					  _this.http.apiResquest({
					  	url: 'api/login/login',
					  	method: 'POST',
						query: {js_code: res.code}
					  }).then(ros=>{
						if(ros.openid){
							  console.log(ros.openid);
							  uni.setStorageSync('openid', ros.openid)
							  uni.redirectTo({
								url: '/pages/index/index'
							  })
						  }else{
							_this.isLogin()
						  }
					  })
					} else {
						_this.isLogin()
				    }
				  }
				})
			}
		}
		
		,checkLogin() {
			let _this = this
			let openid = uni.getStorageSync('openid');
			if(openid){
				return true;
			}else{
				_this.isLogin()
			}
		}
	}
	
}